package com.yuexun.dhdoctor.module.email.presenter.impl;


import com.yuexun.dhdoctor.module.email.bean.MailFileBean;
import com.yuexun.dhdoctor.module.email.bean.SendBean;
import com.yuexun.dhdoctor.module.email.model.IInBoxDetailModel;
import com.yuexun.dhdoctor.module.email.presenter.IInBoxDetailPresenter;
import com.yuexun.dhdoctor.module.email.ui.view.IInBoxView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/8/3.
 */
public class InBoxDetailPresenter implements IInBoxDetailPresenter {
    private IInBoxView view;
    private IInBoxDetailModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public InBoxDetailPresenter(IInBoxDetailModel model, IInBoxView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getFileData(Map<String, String> praise) {
        model.getFileData(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MailFileBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("获取附件信息失败");
                    }

                    @Override
                    public void onNext(MailFileBean mailFileBean) {
                        view.getFileData(mailFileBean);
                    }
                });
    }

    @Override
    public void deleteMail(Map<String, String> praise) {
        model.deleteMail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SendBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("删除邮件失败");
                    }

                    @Override
                    public void onNext(SendBean sendBean) {
                        view.deleteMail(sendBean);
                    }
                });
    }
}
